/**
 * Created by liuyun19 on 2018/12/26.
 */
import Vue from 'vue';
import Vuex from 'vuex';
// 修改state时在console打印，便于调试
import createLogger from 'vuex/dist/logger';

import state from './state'
import getters from './getters'
import mutations from './mutations'
import actions from './actions'

Vue.use(Vuex);

const debug = process.env.NODE_ENV !== 'production';
console.log('dddddddddd',process.env.NODE_ENV, debug)



export default () => {
  const store = new Vuex.Store({
    state,
    getters,
    mutations,
    actions,
    strict: debug, // 严格模式，非法修改state时报错
    plugins: debug ? [createLogger()] : []
  });

  if(module.hot) {
    module.hot.accept([
      './state',
      './getters',
      './mutations',
      './actions'
    ], () => {
      const newState = require('./state').default
      const newMutations = require('./mutations').default
      const newActions = require('./actions').default
      const newGetters = require('./getters').default
      store.hotUpdate({
        state: newState,
        mutations: newMutations,
        actions: newActions,
        getters: newGetters
      })
    })
  }

  return store;
}

